Refactor Dojo Creation Process #731
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a refactor for all code related with dojo creating/updating. I moved large chunks of the code from dojo.py into separate files and did a complete refactor of
dojo_from_spec. My intention behind this PR is to increase the readability and scalability of the dojo creation process by decoupling its parts into separate files.Changes
I separated the majority of
utils/dojo.pyinto a directorydojo_creation, containing five files as follows:dojo_initializer.py:Handles github cloning, loading the yamls, creating the dojo file structure, etc. I basically just copied and pasted large chunks from
dojo.py. This shouldn't introduce any problems because it is mostly existing code. The one small change I did here was I took the final lines ofdojo_from_specand separated them into two separate functions:validate_challenge_pathsandinitialize_course.dojo_builder.py:Contains
DOJO_SPECanddojo_from_spec. Handles initializing everything defined at the top level inside dojo.yml. This is where theDOJO_SPECanddojo_from_specfunctions were relocated. I was able to reduceDOJO_SPECfrom 149 to 33 lines of code anddojo_from_specfrom 164 to 21 lines.module_builder.py:Contains
MODULE_SPECandmodule_from_spec. Handles initializing anything inside of the module.yml or at the module level inside of dojo.yml. This includes initializing all of the module resources.challenge_builder.py:Contains
CHALLENGE_SPECandchallenge_from_spec. You get the idea.builder_utils.py:Contains all helper functions that are used by the
*_builder.pyfiles.Additional Changes:
models/__init.py__:This file had logic relating to importing modules, challenges, and resources. I felt like this functionality was misplaced, so I instead put import functionality into the builder files. The only changes in this file are the deletion of handling the
defaultkeyword argument in theDojoModules,DojoChallengesandDojoResourcesconstructors. These classes are not initialized anywhere besides the dojo init process, so there shouldn't be any side effects from this change.Attribute Inheritance
The attribute inheritance functionality is preserved. If a field is not present in a lower layer of the process (say the challenge layer), it will check all layers above for the field (the module, then the dojo layer).
Imports
The way I structured imports is similar to how it was previously, but not quite the same. The inheritance hierarchy is still there, meaning if a challenge import doesn't specify the module or dojo, it will check the imports in the higher layers. The thing that is different is if importing at a higher layer, like the dojo layer. If the next layer isn't defined, meaning the module list is empty, it will copy over the module list into the dojo data to be handled at the module layer. The module layer then does the same with challenges, with each individual challenge then being imported at the challenge layer. This enables seamless importing of entire dojos.
Consider the following dojo.yml:
This would now essentially clone the entire dojo, instead of creating an empty dojo. You can further specify specific modules of the import as usual:
Which only imports the
hellomodule, which is essentially the same as just:Bug fixes
This PR fixes the following bugs:
dojo_initialize_filesis now fixed.get_challengewere fixed to be more descriptive.I know this is a very big PR, so please let me know if there are any questions or concerns!